<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
<%
	String bathPath = request.getContextPath();
	pageContext.setAttribute("bathPath", bathPath);
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>增加/修改部门</title>
<link rel="stylesheet" href="${bathPath}/frame/layui/css/layui.css">
<link rel="stylesheet" href="${bathPath}/frame/static/css/style.css">
<link rel="icon" href="${bathPath}/frame/static/image/code.png">
<link type="text/css" rel="stylesheet" href="${bathPath}/css/page.css"/>
<script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js" ></script>
<script type="text/javascript" src="${bathPath}/js/ajaxSessionOut.js" ></script>
<!-- 1    css资源 -->
<link rel="stylesheet" type="text/css" href="${bathPath}/js/jquery-easyui-1.4.2/themes/default/easyui.css">
<!-- 2    图标资源 -->
<link rel="stylesheet" type="text/css" href="${bathPath}/js/jquery-easyui-1.4.2/themes/icon.css"> 
<!-- 3    EasyUI的js包 -->
<script type="text/javascript" src="${bathPath}/js/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
<!-- 4    本地语言 -->
<script type="text/javascript" src="${bathPath}/js/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
<!-- layer -->
<link type="text/css" rel="stylesheet" href="${bathPath}/js/layer/skin/layer.css"/>
<script type="text/javascript" src="${bathPath}/js/layer/layer.js" ></script>
<!-- validation -->
<script type="text/javascript" src="${bathPath }/js/jquery-validation/jquery.validate.js"></script>

<script src="${bathPath }/js/quickui/libs/js/form/validationRule.js" type="text/javascript"></script>
<script src="${bathPath }/js/quickui/libs/js/form/validation.js" type="text/javascript"></script>
<script src="${bathPath}/frame/layui/layui.js" charset="utf-8"></script>
<style type="text/css">
	.my-skin .layui-layer-btn a {
	background-color:#009688;
}
</style>

<script type="text/javascript">
function saveBtu(){
	var dID=document.getElementById("depId").value;
	var dName=document.getElementById("depName").value;
	if(dID==0 ||dID==""){
		top.layer.msg("ID不能为空");
	}else if(dName==0 ||dName==""){
		top.layer.msg("名称不能为空");
	}else{
		var param=$("form").serialize();
		$.ajax({
			type:"POST",
			async:false,
			dataType:"text",
			data:param,
			url:"${bathPath}/aDKDept/deptInandUp.action",
			success:function(data){
				layer.confirm("保存成功！", {btn: ['确定'], title: "提示",skin:"my-skin"}, function(){
					parent.layer.close(parent.layer.index);
					parent.location.reload();
					});
				}
			});
		parent.layer.close(parent.layer.index);
		}
	}

//部门层级
layui.use('form', function(){
    var form = layui.form; 
    form.render();
    form.on('select(test)', function(){
    	 // console.log(111111);
    	 // console.log($("#depId").val());
    	  //console.log(222222);
    	  //var dLevel=document.getElementById('level').value;
    	$.ajax({
    		 type:"POST",
    		 async:false,
    		 data:'',
    	     url:"${bathPath}/aDKDept/selectLevel.action?id="+$("#pDepId").val(),
    	     success:function(msg){
    	    	document.getElementById('level').value=1;
     	    	//document.getElementById('level').value=msg[0].level-1;
    	    	for (var i=0; i<msg.length-msg.length+1;i++){
    	    		document.getElementById('level').value=msg[i].level+1;
    	    	}
    	    }
    	});
    	/* $("#level").val("${deptBean.level}") */;
    	});
}); 
</script>
</head>
<body class="body">
<form class="layui-form layui-form-pane"  id="myform" method="post" action="" showOnMouseOver="false">
	<input type="hidden" id="autoId" name="autoId" value="${deptBean.autoId}">
	<table class="param_table">
		<tr>
			<td style="width:250px; padding:3px;">
				<div class="layui-form-item">
       				<label class="layui-form-label" style="width:120px;">部门编号：</label>
       				<div class="layui-input-inline">
            			<input type="text" id="depId" name="depId" value="${deptBean.depId}" lay-verify="required" autocomplete="off" class="layui-input">
            		</div>
            	</div>
            </td>
		</tr>
		<tr>
			<td style="width:250px; padding:3px;">
				<div class="layui-form-item">
       				<label class="layui-form-label" style="width:120px;">部门名称：</label>
       				<div class="layui-input-inline">
            			<input type="text" id="depName" name="depName" value="${deptBean.depName}" lay-verify="required" autocomplete="off" class="layui-input">
            		</div>
            	</div>
            </td>
		</tr>
		<tr >
			<td style="width:250px; padding:3px;">
				<div class="layui-form-item">
       				<label class="layui-form-label" style="width:120px;">上级部门编号：</label>
       				<div class="layui-input-inline">
            			<select type="text" lay-filter="test" id="pDepId" name="pDepId" lay-verify="required"  autocomplete="off" class="layui-input"></select>
            		</div>
            	</div>
            </td>
		</tr>
		<tr >
			<td style="width:250px; padding:3px;">
				<div class="layui-form-item">
       				<label class="layui-form-label" style="width:120px;">部门层级：</label>
       				<div class="layui-input-inline">
            			<input type="text" id="level" name="level" disbaled="" value="${deptBean.level}" lay-verify="required" autocomplete="off" class="layui-input">
            		</div>
            	</div>
            </td>
		</tr>
		<tr >
			<td style="width:250px; padding:3px;">
				<div class="layui-form-item">
       				<label class="layui-form-label" style="width:120px;">归属组织机构：</label>
       				<div class="layui-input-inline">
            			<select type="text" id="netgroupid" name="netgroupid" lay-verify="required"  autocomplete="off" class="layui-input"></select>
            		</div>
            	</div>
            </td>
		</tr>
			<td style="border:0;">
				<input class="layui-btn site-demo-active layui-btn-sm" style="margin-left:305px;" type="button" onclick="saveBtu()" value="保 存"  class="primary"/>
            </td>
		</tr>
	</table>
	</form>
	
<script type="text/javascript">
$(function(){
	$.ajax({
		 type:"POST",
		 async:false,
		 data:"",
	     url:"${bathPath}/aDKNetGroup/selectNetGroupName.action",
	     success:function(msg){
	    	var html="";
	    	html+="<option value=''>"+'请选择所属组织机构'+"</option>";
	    	for (var i = 0; i < msg.length; i++) {
			    html+="<option value='"+msg[i].netgroupid+"'>"+msg[i].netgroupname+'('+msg[i].netgroupid+')'+"</option>";
			}
	    	$("#netgroupid").html(html);
	     }
	 });
	
	//所属组织机构下拉框回填
	$("#netgroupid").val("${deptBean.netgroupid}");
	
	
	//验证名称唯一性
	$("#depName").blur(
		function(){
			var depName = document.getElementById('depName').value;
			//alert("进入keyup");
			$.ajax({
				type:"POST",
				async:true,
				url:"${bathPath}/aDKDept/checkSname.action",
				data : {"depName":depName},
				success:function(data){
						if(data!=0){
							top.layer.msg("名称已存在");
						}
					}
				});
	});
});

$(function(){
	$.ajax({
		 type:"POST",
		 async:false,
		 data:"",
	     url:"${bathPath}/aDKDept/selectDpetName.action",
	     success:function(msg){
	    	var html="";
	    	html+="<option value=''>"+'请选择上级部门'+"</option>";
	    	html+="<option value='@'>"+'@（一级部门）'+"</option>";
	    	/* for (var i = 0; i < msg.length-msg.length+1;i++) {
			    html+="<option value='"+msg[i].pDepId+"'>"+msg[i].pDepId+'（'+'一级部门'+'）'+"</option>";
			} */
	    	for (var i = 0; i <msg.length; i++) {
			    html+="<option value='"+msg[i].depId+"'>"+msg[i].depId+'（'+msg[i].depName+'）'+"</option>";
			}
	    	$("#pDepId").html(html);
	     }
	 });
	
	//上级部门下拉框回填
	$("#pDepId").val("${deptBean.pDepId}");
}); 
</script>
</body>
</html>